package com.yang.service.adminimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yang.bean.MarketStorage;
import com.yang.bean.MarketStorageExample;
import com.yang.bean.common.BasePageInfo;
import com.yang.bean.common.CommonData;
import com.yang.mapper.MarketStorageMapper;
import com.yang.service.admin.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 *
 * @param
 * @return
 * @author BaoZi
 * @since 2022/09/06 21:13
 */
@Service
public class StorageServiceImpl implements StorageService {

    @Autowired
    MarketStorageMapper marketStorageMapper;

    @Override
    public CommonData<MarketStorage> queryList(BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketStorageExample example = new MarketStorageExample();
        example.setOrderByClause(info.getSort() + " " + info.getOrder());
        // mybatis的查询结果
        List<MarketStorage> list =  marketStorageMapper.selectByExample(example);
        PageInfo<MarketStorage> pageInfo = new PageInfo<>(list);
        return CommonData.data(pageInfo);
    }

    @Override
    public void modifyStorage(MarketStorage market) {

        MarketStorageExample example = new MarketStorageExample();
        MarketStorageExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(market.getId());
        marketStorageMapper.updateByExampleSelective(market,example);
    }

    @Override
    public void deleteStorage(MarketStorage market) {
        MarketStorageExample example = new MarketStorageExample();
        MarketStorageExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(market.getId());
        marketStorageMapper.deleteByExample(example);
    }


}
